<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Models\yb\FeedbackModel;
use App\Models\yb\SettingModel;
use App\Models\yb\UserModel;
use Illuminate\Http\Request;


class SetupController extends Controller
{
    /**
     * Get a JWT via given credentials.
     *  意见反馈
     * @return \Illuminate\Http\JsonResponse
     */

    public function FeedbackAdd(Request $request)
    {
        $openid = $request->post('openid');
        $user_data = UserModel::where(['openid'=>$openid])->first();
        if(empty($user_data)){
            return response()->json(['code'=>'401','msg' => '请登录']);
        }

        $content = $request->post('content');

        if(empty($content)){
            return response()->json(['code'=>'201','msg' => '意见不能为空']);
        }

        FeedbackModel::insert([
            'user_id'=>$user_data['id'],
            'openid'=>$openid,
            'nickname'=>$user_data['nickname'],
            'avatar'=>$user_data['avatar'],
            'phone'=>$user_data['phone'],
            'content'=>$content,
            'created_at'=>date('Y-m-d H:i:s',time())
        ]);

        return response()->json(['code'=>'200','msg' => '请求成功']);

    }

    /**
     * Get a JWT via given credentials.
     *  关于我们
     * @return \Illuminate\Http\JsonResponse
     */

    public function AboutUs()
    {
        $setting_data = SettingModel::select('about_us')->first();

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$setting_data]);
    }

    /**
     * Get a JWT via given credentials.
     *  服务协议
     * @return \Illuminate\Http\JsonResponse
     */

    public function ServiceAgreement(Request $request)
    {
        $type = $request->post('type',1);
        if($type == 1){
            $setting_data = SettingModel::select('service_agreement')->first();
        }elseif($type == 2){
            $setting_data = SettingModel::select('privacy_policy as service_agreement')->first();
        }elseif($type == 3){
            $setting_data = SettingModel::select('branch_agreement as service_agreement')->first();
        }elseif($type == 4){
            $setting_data = SettingModel::select('operation_manual as service_agreement')->first();
        }

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$setting_data]);
    }



}
